﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>发布任务</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <link href="../Frozenui1.3/css/frozen.css" rel="stylesheet" />
    <link href="../JS/Date/FT_Date.min.css" rel="stylesheet" />
    
    <script src="../JS/layer/layer.m.js"></script>
    <script src="../JS/zepto.min.js"></script>
    <script src="../Frozenui1.3/js/frozen.js"></script>
    <script src="../JS/avalon.mobile.min.js"></script>
    <script src="../JS/MobileCom.js?v=1.1"></script>

    <script src="../JS/mobiscroll.zepto.js"></script>
    <script src="../JS/mobiscroll.core.js"></script>
    <script src="../JS/mobiscroll.scroller.js"></script>
    <script src="../JS/mobiscroll.datetime.js"></script>
    <script src="../JS/mobiscroll.i18n.zh.js"></script>
    <script src="../JS/jquery.autoTextarea.js"></script>
    <script>
        document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
            //隐藏右上角按钮
            WeixinJSBridge.call('hideOptionMenu');
        });

        var height = 0;
        var width = 0;

        var currYear = (new Date()).getFullYear();
        var opt = {
            date: { preset: 'date' },
            defaultopi: {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                lang: 'zh',
                startYear: currYear - 5, //开始年份
                endYear: currYear + 5, //结束年份
                onSelect: function (valueText, inst) {
                    model.ctData.RWJZDate = valueText;
                }
            }
        };
        function fun(str) {
            $("#jzsj").scroller($.extend(opt['date'], opt['defaultopi'])).scroller('setDate', str, true);
        }


        var model = avalon.define({
            $id: "hdmodel",
            isbj:"",
            ctData: { "LeiBie": "一般", "RWTitle": "", "RWJZDate": "", "RWFZR": "", "RWCYR": "", "Files": "", "RWStatus": "0","TopID":"0" },
            savedata: function () {
                if (model.ctData.LeiBie == "") {
                    $.tips({
                        content: "请输入任务类型",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.RWTitle == "") {
                    $.tips({
                        content: "请输入任务内容",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.RWJZDate == "") {
                    $.tips({
                        content: "请输入截止时间",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                else {
                    if (MobileCom.compareDate(model.ctData.RWJZDate, "")) {
                        $.tips({
                            content: "截止时间必须大于今天",
                            stayTime: 2000,
                            type: "warn"
                        })
                        return;
                    }
                }
                if (model.ctData.RWFZR == "") {
                    $.tips({
                        content: "请输入负责人",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                //if (model.ctData.RWCYR == "") {
                //    $.tips({
                //        content: "请输入参与人",
                //        stayTime: 2000,
                //        type: "warn"
                //    })
                //    return;
                //}
                var lg = $.loading({
                    content: '保存中...',
                })
                $.post("/API/WXAPI.ashx?Action=ADDRCTX&r=" + Math.random(), { "P1": JSON.stringify(model.ctData.$model) }, function (data) {
                    lg.hide();
                    var data = $.parseJSON(data);
                    if (data.ErrorMsg == "") {
                        $(".ui-footer").hide();
                        var el = $.tips({
                            content: "保存成功！",
                            stayTime: 2000,
                            type: "success"
                        })
                        el.on("tips:hide", function () {
                            //window.location.reload();
                            if (model.isbj == "") {
                                if (model.ctData.TopID != "0") {
                                    window.location.replace("UI_DBSX_INFO.html?ID=" + model.ctData.TopID + "&r=" + Math.random());
                                }
                                else {
                                    window.location.replace(location.href);
                                }
                            }
                            else {
                                window.location.replace("UI_DBSX_LIST.html?r=" + Math.random());
                            }

                        })
                    }
                    else {
                        $.tips({
                            content: "保存失败，原因：" + data.ErrorMsg,
                            stayTime: 2000,
                            type: "warn"
                        })
                    }
                })
            },
            repshow: function () {
                $(this).parent().siblings().removeClass("active");
                $(this).parent().addClass("active");
            },
            selperson: function () {
                fzcy = $(this);
                $("#content").hide();
                if (fzcy.attr("id") == "rw_fzry") {
                    $("#iframef").show();

                    var cheight = height;
                    var cwidth = width;

                    $("#iframef").css("height", cheight);
                    $("#iframef").css("width", cwidth);
                }
                else {
                    $("#iframec").show();

                    var cheight = height;
                    var cwidth = width;

                    $("#iframec").css("height", cheight);
                    $("#iframec").css("width", cwidth);
                }

            },
            bjk: function () {

                var tc = layer.open({
                    type: 1,
                    //content:$("#bmxx").html(),
                    //title: "活动简介",
                    content: '<div class="ui-form-item ui-form-item-textarea ui-border-b" style="width:' + (width - 76) + 'px;height:200px"><textarea id="hdjjbjk" style="padding-left: 0;height:170px;border: 1px solid #e0e0e0;" placeholder="请输入任务内容">' + model.ctData.RWTitle + '</textarea></div>',
                    btn: ['确认', '取消'],
                    shadeClose: false,
                    yes: function () {
                        model.ctData.RWTitle = $("#hdjjbjk").val();
                        if ($("#hdjjbjk").val() != "") {
                            $("#hdjj").removeClass("ui-txt-muted");
                            $("#hdjj").html($("#hdjjbjk").val());
                        }
                        else {
                            $("#hdjj").addClass("ui-txt-muted");
                            $("#hdjj").html("请输入任务内容");
                        }

                        layer.close(tc);

                    }, no: function () {
                    }
                })
                $("#hdjjbjk").focus();
            }

        });
        var fzcy = "";
        function goback() {
            $("#content").show();
            $("#iframef").hide();
            $("#iframec").hide();
        }
        function goconfirm(json) {
            if (json != null) {
                fzcy.removeClass("ui-txt-muted");
                fzcy.html(json.vuser);
                if (fzcy.attr("id") == "rw_fzry") {
                    model.ctData.RWFZR = json.vusername;
                }
                else {
                    model.ctData.RWCYR = json.vusername;
                }
            }
            else {
                fzcy.addClass("ui-txt-muted");
                if (fzcy.attr("id") == "rw_fzry") {
                    fzcy.html('请输入负责人');
                    model.ctData.RWFZR = '';
                }
                else {
                    fzcy.html('请输入参与人');
                    model.ctData.RWCYR = '';
                }
            }

            $("#content").show();
            $("#iframef").hide();
            $("#iframec").hide();
        }

        avalon.ready(function () {
            var strId = MobileCom.getQueryString("ID");
            var strTopId = MobileCom.getQueryString("TopID");
            if (strTopId) { model.ctData.TopID = strTopId }

            width = document.documentElement.clientWidth;
            height = document.documentElement.clientHeight;
            //$("#iframef").attr("src", "UI_PERSON.html?r=" + Math.random());
            $("#iframec").attr("src", "UI_PERSON.html?r=" + Math.random());

            var lg = $.loading({
                content: '加载中...',
            })
            if (strId) {
                model.isbj = "Y";
                $("#save").text("保存");
                $("title").text("修改任务待办");

                $.getJSON('/API/WXAPI.ashx?Action=GETRCTXMODEL&r=' + Math.random(), { P1: strId }, function (resultData) {
                    
                    if (resultData.ErrorMsg == "") {
                        var n = 0;
                        model.ctData = resultData.Result;

                        if (model.ctData.RWTitle) {
                            $("#hdjj").removeClass("ui-txt-muted");
                            $("#hdjj").html(model.ctData.RWTitle);
                        }

                        if (model.ctData.RWFZR) {
                            $("#iframef").attr("src", "UI_PERSON.html?r=" + Math.random() + "&Users=" + model.ctData.RWFZR + "&Type=1");

                            $.getJSON('/API/SZHLAPI.ashx?Action=GETUSERSBYUSERNAME&r=' + Math.random(), { P1: model.ctData.RWFZR }, function (data) {
                                n = n + 1;
                                if (n == 2) { lg.hide(); }
                                if (data.ErrorMsg == "") {
                                    $("#rw_fzry").removeClass("ui-txt-muted");
                                    $("#rw_fzry").html(data.Result[0].UserRealName);
                                }
                            })
                        }
                        else {
                            n = n + 1;
                            if (n == 2) { lg.hide(); }
                        }

                        if (model.ctData.RWCYR) {
                            $("#iframec").attr("src", "UI_PERSON.html?r=" + Math.random() + "&Users=" + model.ctData.RWCYR);

                            $.getJSON('/API/SZHLAPI.ashx?Action=GETUSERSBYUSERNAME&r=' + Math.random(), { P1: model.ctData.RWCYR }, function (data) {
                                n = n + 1;
                                if (n == 2) { lg.hide(); }
                                if (data.ErrorMsg == "") {
                                    var html = '';
                                    for (var i = 0; i < data.Result.length; i++) {
                                        if (html) {
                                            html = html + ',' + data.Result[i].UserRealName;
                                        }
                                        else {
                                            html = data.Result[i].UserRealName
                                        }
                                    }
                                    $("#rw_cyry").removeClass("ui-txt-muted");
                                    $("#rw_cyry").html(html);
                                }
                            })
                        }
                        else {
                            n = n + 1;
                            if (n == 2) { lg.hide(); }
                        }

                        var arr1 = model.ctData.RWJZDate.substring(0, 10).split("-");
                        var time1 = new Date(arr1[0], arr1[1] - 1, arr1[2]);

                        fun(time1);
                        model.ctData.RWJZDate = model.ctData.RWJZDate.substring(0, 10);

                    }
                    else {
                        lg.hide();
                    }
                })
            } else {
                fun(new Date(new Date().setDate(new Date().getDate() + 1)));
                model.ctData.RWJZDate = $("#jzsj").val();

                $.post("/API/SZHLAPI.ashx?Action=GetUserInfo&r=" + Math.random(), {}, function (data) {
                    lg.hide();
                    var data = $.parseJSON(data);
                    if (data.ErrorMsg == "") {
                        model.ctData.RWFZR = data.Result.User.UserName;
                        $("#rw_fzry").removeClass("ui-txt-muted");
                        $("#rw_fzry").html(data.Result.User.UserRealName);
                        $("#iframef").attr("src", "UI_PERSON.html?r=" + Math.random() + "&Users=" + data.Result.User.UserName + "&Type=1");
                    }
                })
            }
            $(".chackTextarea-area").autoTextarea({
                maxHeight: 220,
                minHeight: 80
            });
        })
        function back() {
            window.location.replace("UI_DBSX_LIST.html?r=" + Math.random());
        }
    </script>
    <style type="text/css">
        .ui-select {
            border: none;
            border: 0;
            background-color: #fff;
            appearance: none;
            -moz-appearance: none; /* Firefox */
            -webkit-appearance: none; /* Safari 和 Chrome */
        }
        .ms-controller, [ms-controller] {
            display: none;
        }
    </style>
</head>
<body ms-controller="hdmodel">
    <div id="content">
        <header ms-if="isbj" class="ui-header ui-header-stable ui-border-b">
            <i class="ui-icon-return" onclick="history.back(-1)"></i>
            <h1>任务待办修改</h1>
        </header>

        <div class="ui-footer ui-footer-stable ui-btn-group ui-border-t">
            <button  class="ui-btn-lg" onclick="history.back(-1)">
                取消
            </button>
            <button class="ui-btn-lg ui-btn-primary" ms-click="savedata()" id="save">
                发布任务
            </button>
        </div>

        <section class="ui-container">
            <div class="ui-form ui-border-t">
                <div class="ui-form-item ui-border-b">
                    <label>
                        任务类型
                    </label>
                    <div class="ui-select ui-border-b">
                        <select ms-duplex="ctData.LeiBie">
                            <option value="一般">一般</option>
                            <option value="重要">重要</option>
                        </select>
                    </div>
                </div>
                <div class="ui-form-item ui-border-b ui-form-item-textarea" style="height:auto;min-height:44px">
                    <label>
                        任务内容
                    </label>
                    <textarea placeholder="请输入任务内容" style="height:80px;" class="chackTextarea-area" ms-duplex="ctData.RWTitle"></textarea>
                    <!--<div class="ui-txt-muted ui-whitespace " style="padding-left: 95px;text-align:justify" id="hdjj" ms-click="bjk()">请输入任务内容</div>-->
                    <!--<input type="text" placeholder="请输入任务内容" ms-duplex="ctData.RWTitle" />-->
                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        截止时间
                    </label>
                    <div class="ui-select ui-border-b">
                        <input type="text" placeholder="请输入截止时间" ms-duplex="ctData.RWJZDate" id="jzsj" style="padding-left:0" />

                    </div>
                </div>
                <div class="ui-form-item ui-border-b" style="height:auto">
                    <label>
                        负责人
                    </label>
                    <div class="ui-txt-muted ui-whitespace ui-form-item-link" style="padding-left: 95px;text-align:justify" id="rw_fzry" ms-click="selperson()">请选择负责人</div>

                </div>
                <div class="ui-form-item ui-border-b" style="height:auto">
                    <label>
                        参与人
                    </label>
                    <div class="ui-txt-muted ui-whitespace ui-form-item-link" style="padding-left: 95px;text-align:justify" id="rw_cyry" ms-click="selperson()">请选择参与人</div>
                </div>
                <!--<div class="ui-form-item ui-border-b">
                    <label>
                        图片
                    </label>
                </div>
                <div class="ui-form-item ui-form-item-textarea ui-border-b">
                    <a class="ui-icon-add"></a>
                </div>-->

            </div>
        </section>
    </div>


    <iframe id="iframef" src="UI_PERSON.html" style="display: none; margin-bottom: -7px;" frameborder="0"></iframe>
    <iframe id="iframec" src="UI_PERSON.html" style="display: none; margin-bottom: -7px;" frameborder="0"></iframe>
</body>
</html>
